# -*- coding: UTF-8 -*-
# Author: Damon(wuud1)
# CreateDate: 
# Message:  标致雪铁龙图片转png
import os
from PIL import Image


class CitroenImg:

    def __init__(self, brand="citroen"):

        self.srcPath = os.getcwd() + os.sep + '..' + os.sep + 'citroenImg' + os.sep + brand
        self.destPath = os.getcwd() + os.sep + '..' + os.sep + 'PNG' + os.sep + brand
        if not os.path.exists(self.destPath):
            os.makedirs(self.destPath)

    def jpg2png(self, src, dest):
        img = Image.open(src)
        img.save(dest)
        print("success")

    def run(self):
        # 获取cid文件夹列表
        cidFolders = os.listdir(self.srcPath)
        for cid in cidFolders:
            if "DS_Store" in cid:
                continue
            srcCidPath = self.srcPath + os.sep + cid
            destCidPath = self.destPath + os.sep + cid
            if not os.path.exists(destCidPath):
                os.makedirs(destCidPath)
            # 获取图片列表
            imgFiles = os.listdir(srcCidPath)
            for img in imgFiles:
                if "DS_Store" in img:
                    continue
                srcImgPath = srcCidPath + os.sep + img
                destImgPaht = (destCidPath + os.sep + img)[:-4] + '.png'
                if os.path.exists(destImgPaht):
                    continue
                try:
                    print(srcImgPath, destImgPaht)
                    self.jpg2png(srcImgPath, destImgPaht)
                except Exception as e:
                    print(srcImgPath, "error")
                    print(e.__repr__())

def main():
    brand = "peugeot"  # citroen
    tools = CitroenImg(brand=brand)
    tools.run()

if __name__ == '__main__':
    main()

